package com.lc.afbx.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/6/23.
 */
@HttpInlet(Conn.INLET_API_SHOW_ICOMPANY)
public class GetApiShowICompany extends BaseAsyGet<GetApiShowICompany.Info> {
    public String tid;

    public GetApiShowICompany(AsyCallBack<GetApiShowICompany.Info> asyCallBack) {
        super(asyCallBack);
    }

    protected Info parser(JSONObject jsonObject) {

        TOAST = jsonObject.optString("message");

        if (jsonObject.optInt("code") == 200) {

            Info info = new Info();

            info.code = jsonObject.optString("code");
            info.message = jsonObject.optString("message");

            JSONArray array = jsonObject.optJSONArray("data");

            for (int i = 0; i < array.length(); i++) {

                JSONObject o = array.optJSONObject(i);
                Data data = new Data();

                data.id = o.optString("id");
                data.title = o.optString("title");
                data.picurl = Conn.PIC + o.optString("picurl");
                data.privilege = o.optString("privilege");

                info.dataList.add(data);
            }

            return info;
        }
        return null;
    }


    public static class Info {

        public String message, code;
        public List<Data> dataList = new ArrayList<>();

    }

    public static class Data implements Serializable {
        //        "id": "1",
//                "title": "平安保险",
//                "picurl": "/Uploads/20160517/pic_573ade3e63048.png",
//                "privilege": "赠品XXXXXXXX"
        public String id, title, picurl, privilege;
    }
}
